package com.library.web.controller.library;

import com.library.common.annotation.Log;
import com.library.common.core.controller.BaseController;
import com.library.common.core.domain.AjaxResult;
import com.library.common.core.page.TableDataInfo;
import com.library.common.enums.BusinessType;
import com.library.common.utils.poi.ExcelUtil;
import com.library.domain.BoBookType;
import com.library.service.IBoBookTypeService;
import com.qcloud.cos.thirdparty.org.bouncycastle.LICENSE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


/**
 * 图书类型管理 信息操作处理
 *
 * @author wanghongjie
 * @date 2020-01-18
 */
@RestController
@RequestMapping("/library/bookType")
public class BoBookTypeController extends BaseController {
    private String prefix = "business/library/boBookType";

    @Autowired
    private IBoBookTypeService boBookTypeService;



    /**
     * 查询图书类型管理列表
     */
    @PreAuthorize("@ss.hasPermi('library:bookType:list')")
    @GetMapping("/list")
    public TableDataInfo list(BoBookType boBookType) {
        startPage();
        List<BoBookType> list = boBookTypeService.selectBoBookTypeList(boBookType);
        return getDataTable(list);
    }

    /**
     * 导出图书类型管理列表
     */
    @PreAuthorize("@ss.hasPermi('library:bookType:export')")
    @Log(title = "图书类型管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BoBookType boBookType) {
        List<BoBookType> list = boBookTypeService.selectBoBookTypeList(boBookType);
        ExcelUtil<BoBookType> util = new ExcelUtil<BoBookType>(BoBookType.class);
        util.exportExcel(response, list, "图书类型管理数据");
    }

    /**
     * 获取图书类型管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('library:bookType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(boBookTypeService.selectBoBookTypeById(id));
    }

    /**
     * 新增图书类型管理
     */
    @PreAuthorize("@ss.hasPermi('library:bookType:add')")
    @Log(title = "图书类型管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BoBookType boBookType) {
        return toAjax(boBookTypeService.insertBoBookType(boBookType));
    }

    /**
     * 修改图书类型管理
     */
    @PreAuthorize("@ss.hasPermi('library:bookType:edit')")
    @Log(title = "图书类型管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BoBookType boBookType) {
        return toAjax(boBookTypeService.updateBoBookType(boBookType));
    }

    /**
     * 删除图书类型管理
     */
    @PreAuthorize("@ss.hasPermi('system:bookType:remove')")
    @Log(title = "图书类型管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(boBookTypeService.deleteBoBookTypeByIds(ids));
    }

    /**
     * 校验图书类型编号是否重复
     */
    @PostMapping("/checkBookTypeNo")
    @ResponseBody
    public String checkBookTypeNoUnique(BoBookType boBookType) {
        return boBookTypeService.checkBookTypeNoUnique(boBookType);
    }

    /**
     * 校验图书类型名称是否重复
     */
    @PostMapping("/checkBookTypeName")
    @ResponseBody
    public String checkBookTypeNameUnique(BoBookType boBookType) {
        return boBookTypeService.checkBookTypeNameUnique(boBookType);
    }
}
